// TDS Sensor of Humidity and Temperature

//******************************************************************************************
//******************************************************************************************
//******************************************************************************************
//******************************************************************************************
//*****	TDS SENSOR TEMP & HUMIDITY SOFTWARE					       *****
//*****	GRUPO DIANA. UNIVERSIDAD DE MÁLAGA					       *****
//*****	VERSIÓN 0.1								       *****
//******************************************************************************************
//******************************************************************************************
//******************************************************************************************
//******************************************************************************************



#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to  (cable amarillo)

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (cable rojo) of the sensor to pin3 of arduino (we will set this pin as output and high level)
// Connect pin 2 (cable amarillo) of the sensor to whatever your DHTPIN is (pin2 de arduino en este caso)
// Connect pin 4 (cable negro) of the sensor to GROUND in arduino
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200); 
  Serial.println("DHTxx test!");
  
  // We set the pin 3 of arduino as output and high level
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
 
  dht.begin();
}

void loop() {
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  //float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  //if (isnan(h) || isnan(t) || isnan(f)) {
  if (isnan(h) || isnan(t)) {
    //Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  //float hi = dht.computeHeatIndex(f, h);

  Serial.print("H: "); 
  Serial.print(h);
  Serial.print("; ");
  Serial.print("T: "); 
  Serial.print(t);
  Serial.println("");
  /*Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");*/
  
  // Wait a few seconds between measurements.
  delay(3000);
}
